<!--
 - Copyright 2022. Huawei Technologies Co., Ltd. All rights reserved.

 - Licensed under the Apache License, Version 2.0 (the "License");
 - you may not use this file except in compliance with the License.
 - You may obtain a copy of the License at

 -   http://www.apache.org/licenses/LICENSE-2.0

 - Unless required by applicable law or agreed to in writing, software
 - distributed under the License is distributed on an "AS IS" BASIS,
 - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 - See the License for the specific language governing permissions and
 - limitations under the License.
 -->

 <template>
    <div id="app" :style="customStyle">
        <div v-if="!logined" class="loading">
            <img :src="loadingImg" class="loading_img" :class="{'rtl-l': $rtl}"/>
        </div>
        <router-view v-else></router-view>
    </div>
</template>

<script>
export default {
    name: "App",
    data() {
        return {
            customStyle: {
                paddingTop: window.topHeight+'px',
                "overflow": "hidden auto",
            },
            logined: false,
            loadingImg: window.isDark ? require("@/assets/image/dark/loading_dark.gif") : require("@/assets/image/loading_light.gif")
        }
    },
    created() {
        let htmlStyle = document.documentElement.style;
        if (window.isDark) {
            htmlStyle.setProperty(
                "--bg-color",
                "rgba(0,0,0,1)"
            );
            htmlStyle.setProperty(
                "--text-color",
                "rgba(255,255,255,0.6)"
            );
            htmlStyle.setProperty(
                "--border-color",
                "rgba(255,255,255,0.1)"
            );
        } else {
            htmlStyle.setProperty(
                "--bg-color",
                "rgba(241,243,245,1)"
            );
            htmlStyle.setProperty(
                "--text-color",
                "#000000"
            );
            htmlStyle.setProperty(
                "--border-color",
                "rgba(0,0,0,0.1)"
            );
        }

        if(this.$rtl) htmlStyle.setProperty("transform", "scaleX(-1)");
    },
    mounted() {
        if (process.env.NODE_ENV == "development") {
            this.logined = true;
            return;
        }
        window.BasicLib.account
            .signIn({
                appid: this.globalData.APP_ID, // 联盟上申请到的APPID
                useAuthCode: false,
                scopes: [
                    // 根据业务添加所需SCOPE
                    "https://www.huawei.com/healthkit/extend/device.read"
                ],
            })
            .then(signInResult => {
                // 登录成功，signInResult结果中包含了openId、AT、用户帐号基本信息
                console.log("login success result", signInResult);
                this.logined = true;
            })
            .catch(err => {
                BasicLib.container.exit();
                console.error("login error:", err);
            });
    },
};
</script>

<style>
#app {
    height: 100%;
    width: 100%;
    background-color: var(--bg-color) !important;
    color: var(--text-color) !important;
}

html,
body {
    height: 100%;
    width: 100%;
    overflow: hidden;
}
</style>
